package com.xry.controller;

import com.xry.bean.Order;
import com.xry.service.OrderService;
import com.xry.util.Page;
import com.xry.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @PostMapping
    public Result add(@RequestBody Order order){
        Object obj=orderService.add(order);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Order order){
        Object obj=orderService.edit(order);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj=orderService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id")Integer id){
        Object obj=orderService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all( Order order){
        Object obj=orderService.all(order);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Order order){
        //查询一共有多少条数据
        //查询当前页要显示的数据
        //将当前页封装到page对象中
        orderService.page(page,order);
        //返回page对象
        return Result.success(page);
    }

    @GetMapping("cdate")
    public Result countByDate(){
        Object obj=orderService.countByDate();
        return Result.success(obj);
    }

    @GetMapping("camount")
    public Result countAmount(){
        Object obj=orderService.countAmount();
        return Result.success(obj);
    }

}